package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "globle_fallback")
public class OrderFeignController {

    @Autowired
    PaymentFeignService paymentFeignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id)
    {
        String result = paymentFeignService.paymentInfo_OK(id);
        log.info("****result: "+result);
        return result;
    }

    @GetMapping("/consumer/payment/hystrix/timeout/get/{id}")
    @HystrixCommand(fallbackMethod = "aaa", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
    })
    public String paymentInfo_Timeout(@PathVariable("id") Long id) {
        String paymentHystrixById = paymentFeignService.paymentInfo_Timeout(id);
        log.info("****"+paymentHystrixById);
        return paymentHystrixById;
    }

    public String aaa(@PathVariable("id") Long id) {
        log.info("我是消费者80");
        return "我是消费者80,对方支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,o(╥﹏╥)o";
    }
//    public String globle_fallback() {
//        log.info("globle_fallback");
//        return "globle_fallback, o(╥﹏╥)o";
//    }


}
